package testing;

import java.util.Scanner;

public class MatrixTranspose {

		public static void main(String[] args)
		{
			//declare all variables/arrays
			int idx1, idx2;
			int[][] array, matrix;	
	 
			//set up the scanner and get the number of rows and columns in the array
			Scanner scan = new Scanner(System.in);
			System.out.print("Enter number of rows: ");
			idx1 = scan.nextInt();
			System.out.print("Enter number of columns: ");
			idx2 = scan.nextInt();
			
			//set the size 
			array = new int[idx1][idx2];
			matrix = new int[idx2][idx1];
			
			for(int j = 0; j < idx1; j++)
			{	
				System.out.println("Enter " + idx2 + " elements for row " + (j + 1) + ":");
				for(int k = 0; k < idx2; k++)
				{	
					array[j][k] = scan.nextInt();
				}
			}		
	 
	 
			
	 		//matrix = array;
	 		for(int h = 0; h < idx1; h++)
	 		{	
				for(int i = 0; i < idx2; i++)
	     		{
					matrix[i][h] = array[h][i];
				}
			}
	 		
			System.out.println("The original matrix is ->");
			
			for(int l = 0; l < idx1; l++)
			{	
				for(int m = 0; m < idx2; m++)
				{
					System.out.print("[" + array[l][m] + "]");	
				}
				System.out.println();
			}		
			System.out.println("The tranpose matrix is ->");
					
			for(int l = 0; l < idx2; l++)
			{	
				for(int m = 0; m < idx1; m++)
				{
					System.out.print("[" + matrix[l][m] + "]");	
				}
				System.out.println();
			}		
		}
	}

